function handleResponse(
  response,
  handleSuccess = () => {},
  handleFail = () => {},
) {
  if (isPlainObject(response)) {
    const { success, message, data } = response;
    if (success) {
      if (isFunction(handleSuccess)) {
        handleSuccess(data);
      }
    } else {
      notification.error({
        message: message || "操作失败",
      });
      if (isFunction(handleFail)) {
        handleFail();
      }
    }
  }
}

function handleGanttDataReceive(data, day, extraData) {
  const { stopType } = extraData;
  const ganttData = [];
  if (isPlainObject(data)) {
    const { docks } = data;
    if (isArray(docks)) {
      // 遍历月台
      for (let i = 0; i < docks.length; i++) {
        const dock = docks[i];
        if (isPlainObject(dock)) {
          const row = {};
          const {
            locationName,
            locationGid,
            name: dockName,
            id: dockGid,
            dockResourceLineList,
            appointmentActivityType,
          } = dock;
          row.id = `${i + 1}`;
          row.render = "split";
          row.start_date = moment(`${day} 00:00:00`).format("YYYY-MM-DD HH:mm");
          row.end_date = moment(`${day} 00:00:00`).format("YYYY-MM-DD HH:mm");
          row.duration = 0;
          row.isSelected = false;
          row.locationName = locationName;
          row.locationGid = locationGid;
          row.dockName = dockName;
          row.dockGid = dockGid;
          row.enable =
            appointmentActivityType === "PD"
              ? true
              : appointmentActivityType === stopType;
          ganttData.push(row);
          if (isArray(dockResourceLineList)) {
            // 遍历时间窗
            for (let j = 0; j < dockResourceLineList.length; j++) {
              const slideWindow = dockResourceLineList[j];
              if (isPlainObject(slideWindow)) {
                const item = {};
                const {
                  dimension,
                  remainingCapacity,
                  id: dockResourceLineGid,
                  fromSlot,
                  toSlot,
                } = slideWindow;
                item.parent = `${i + 1}`;
                item.id = `${i + 1}.${j + 1}`;
                item.dimension = dimension;
                item.count = isNumber(remainingCapacity)
                  ? remainingCapacity
                  : 0;
                item.locationGid = locationGid;
                item.dockGid = dockGid;
                item.dockResourceLineGid = dockResourceLineGid;
                item.isSelected = false;
                item.parentEnable = row.enable;
                item.enable = row.enable && item.count > 0;
                item.start_date = handleSlideWindow(day, fromSlot);
                item.end_date = handleSlideWindow(day, toSlot);
                item.appointmentDate = `${day} 00:00:00`;
                ganttData.push(item);
              }
            }
          }
        }
      }
    }
  }
  return ganttData;
}

function findX(data, minuteStep = 10) {
  let x = 0;
  const times = [];
  if (isPlainObject(data)) {
    const { docks } = data;
    if (isArray(docks)) {
      for (let i = 0; i < docks.length; i++) {
        const dock = docks[i];
        if (isPlainObject(dock)) {
          const { dockResourceLineList } = dock;
          if (isArray(dockResourceLineList)) {
            for (let j = 0; j < dockResourceLineList.length; j++) {
              const win = dockResourceLineList[j];
              if (isPlainObject(win)) {
                const { fromSlot } = win;
                let fromTimeValue = 0;
                if (!isNil(fromSlot) && !isNaN(Number(fromSlot))) {
                  fromTimeValue = Number(fromSlot);
                }
                times.push(fromTimeValue);
              }
            }
          }
        }
      }
    }
  }
  const newTimes = sortBy(times);
  if (newTimes.length) {
    x = newTimes[0];
  }
  const minWid = 20;
  x = parseInt((x / 60 / minuteStep) * minWid, 10);
  return x;
}
